package com.wjs.blog.service;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.wjs.blog.dao.mapper.ArticleMapper;
import com.wjs.blog.dao.pojo.Article;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class ThreadService {
    @Async("taskExecutor")
    public void updateArticleViewCount(ArticleMapper articleMapper, Article article) {
        int viewCounts = article.getViewCounts();
        Article articleupdate=new Article();
        articleupdate.setViewCounts(viewCounts+1);
        LambdaUpdateWrapper<Article> wrapper=new LambdaUpdateWrapper<>();
        wrapper.eq(Article::getId,article.getId()).eq(Article::getViewCounts,article.getViewCounts());
        articleMapper.update(articleupdate,wrapper);
    }
}
